import mapSelection from '../components/map-selection'

export const selectionMixin = {
  components: {
    mapSelection
  },
  data() {
    return {
      mapSelectionVisible: false,
      selection: {
        staff: [],
        case: [],
        car: [],
        video: []
      }
    }
  },
  methods: {
    /**
     * @Author ling.yuan@topevery.club
     * @Date 2019/12/11 19:31:33
     * @Description 重置已选择数据并关闭选择概况
     */
    handleCloseMapSelection(flag = false) {
      this.handleResetSelection()
      this.mapSelectionVisible = flag
    },
    /**
     * @Author ling.yuan@topevery.club
     * @Date 2019/12/11 19:31:51
     * @Description 处理选中的数据并传递到概况
     */
    handleDefaultSelection(extent, features) {
      this.handleResetSelection()

      this.$refs.caseBar.handleCloseCaseInfo()
      this.$refs.staffBar.handleStaffAllHide()
      this.$refs.carBar.handleCloseCarDetail()
      this.$refs.videoBar.handleCloseVideoDetail()

      this.$refs.mapSelection.closeBackAndShowOverview()
      features.forEach(item => {
        const tmp = item.getProperties()
        this.selection[tmp.target].push(tmp.id)
      })
      this.mapSelectionVisible = true
    },
    /**
     * @Author ling.yuan@topevery.club
     * @Date 2019/12/11 19:32:01
     * @Description 重置选中的数据
     */
    handleResetSelection() {
      for (const item in this.selection) {
        this.selection[item] = []
      }
    },
    handleSelectionPositionAndShowDetail(event, target) {
      if (target === 'case') {
        this.handleCasePositionAndShowDetail(event)
      } else if (target === 'staff') {
        this.handleStaffPositionAndShowDetail(event)
      } else if (target === 'video') {
        this.handleVideoPositionAndShowDetail(event)
      } else if (target === 'car') {
        this.handleCarPositionAndShowDetail(event)
      }
    },
    handleCasePositionAndShowDetail(event) {
      this.handleCasePosition(event)
      this.handleCaseClick(event)
    },
    handleVideoPositionAndShowDetail(event) {
      this.handleVideoPosition(event)
      this.handleVideoClick(event)
    },
    handleCarPositionAndShowDetail(event) {
      this.handleCarPosition(event)
      this.handleCarClick(event)
    },
    handleStaffPositionAndShowDetail(event) {
      this.handleStaffPosition(event)
      this.handleStaffClick(event)
    }
  }
}
